function TreeNode(val, left, right) {
    this.val = (val===undefined ? 0 : val)
     this.left = (left===undefined ? null : left)
      this.right = (right===undefined ? null : right)
  }



nums = [-10,-3,0,5,9]



var sortedArrayToBST = function(nums) {
    if(nums.length===0)return null
    const mid=Math.floor(nums.length/2)
    const res = new TreeNode(nums[mid])
    res.left= sortedArrayToBST(nums.slice(0,mid))
    res.right=sortedArrayToBST(nums.slice(mid+1))
    return res
}

console.log(sortedArrayToBST(nums));
